package org.hbs.blog.code.util;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class PageBean<T> implements Serializable {

	private static final long serialVersionUID = -893101005797809967L;

	private Integer currPage;
	private Integer nextPage;
	private Integer prevPage;

	private Integer maxCount;
	private Integer pageSize;
	private Integer maxPage;

	private List<T> items = new ArrayList<T>();

	public PageBean(Integer currPage, Integer pageSize,Integer maxCount) {
		
		this.currPage = currPage;
		this.pageSize = pageSize;
		this.maxCount = maxCount;

		this.maxPage = this.maxCount % pageSize == 0 ? this.maxCount / pageSize
				: this.maxCount / pageSize + 1;
		this.prevPage = currPage - 1 < 1 ? 1 : currPage - 1;
		this.nextPage = currPage + 1 > maxPage ? currPage : currPage + 1;
	}

	public Integer getPrevPage() {
		return this.prevPage;
	}

	public Integer getNextPage() {
		return this.nextPage;
	}
	
	public Integer getCurrPage(){
		return this.currPage;
	}
	
	public Integer getPageSize(){
		return this.pageSize;
	}
	
	public Integer getMaxCount(){
		return this.maxCount;
	}
	
	public Integer getMaxPage(){
		return this.maxPage;
	}

	public List<T> getItems() {
		return items;
	}

	public List<T> setItems(List<T> items) {
		this.items = items;
		return this.items;
	}
	
	public List<T> addItem(T item){
		this.items.add(item);
		return this.items;
	}
	
}
